package com.xiaxueqi.web.home;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.niagara.context.SecurityContext;
import com.niagara.dao.Page;
import com.niagara.security.auth.entity.UserDetail;
import com.niagara.service.base.BaseService;
import com.niagara.web.struts2.CRUDActionSupport;
import com.niagara.web.struts2.Struts2Utils;
import com.xiaxueqi.entity.book.Address;
import com.xiaxueqi.entity.book.ShopOrder;

/**
 * 登录用户购物订单的管理
 * 
 * @author liangThink
 * 
 */
public class ShoppingOrderAction extends CRUDActionSupport<ShopOrder> {
	private static final long serialVersionUID = 1L;

	@Autowired
	private BaseService baseService;
	private Integer id;
	private ShopOrder shopOrder;
	private Page<ShopOrder> page;
	private List<Address> addressList;

	private UserDetail detail = SecurityContext.getUserDetail();
	private Integer userId = detail != null ? Integer.valueOf(detail
			.getUserId().intValue()) : null;

	@Override
	public String delete() throws Exception {
		return null;
	}

	@Override
	public String list() throws Exception {
		Map map = Struts2Utils.getParameters();
		Integer pageNo = Struts2Utils.getIntParameter(PARAMS_PAGENO, Integer
				.valueOf(1));
		map.put("buyerId", userId);
		page = this.baseService.findForPaging(ShopOrder.class, map, pageNo, 15);
		return SUCCESS;
	}

	@Override
	protected void prepareModel() throws Exception {
		if (id != null) {
			shopOrder = this.baseService.get(ShopOrder.class, id);
		} else {
			shopOrder = new ShopOrder();
		}
	}

	@Override
	public String save() throws Exception {
		return null;
	}

	public ShopOrder getModel() {
		return this.shopOrder;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public ShopOrder getShopOrder() {
		return shopOrder;
	}

	public Page<ShopOrder> getPage() {
		return page;
	}

	public Integer getUserId() {
		return userId;
	}

	public List<Address> getAddressList() {
		return addressList;
	}
}
